<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
	<th:block th:include="include :: header('运行参数设置')"/>
</head>
<style>
	.layui-form-label {
		width: 150px !important;
		text-align: left !important;
	}

	.layui-form-item .layui-input-inline {
		width: 300px !important;
		margin-bottom: 0px !important;
	}

	.layui-form-item-te {
		margin-bottom: 0px !important;
	}
</style>
<form class="layui-form layui-form-pane" action="" id="statusform" lay-filter="statusform">
	<div class="layui-form-item layui-form-item-te" style="padding-left: 30%;padding-top: 5%;">
		<label class="layui-form-label">台站编号:</label>
		<div class="layui-input-inline">
			<input type="text" id="stationCode" name="stationCode" lay-verify="required"
				   autocomplete="off"
				   class="layui-input" readonly>
		</div>
	</div>
	<div class="layui-form-item layui-form-item-te" style="padding-left: 30%;padding-top: 1%;">
		<label class="layui-form-label">发射机代码:</label>
		<div class="layui-input-inline">
			<input type="text" id="transCode" name="transCode" lay-verify="required"
				   autocomplete="off"
				   class="layui-input" readonly>
		</div>
	</div>
	<div class="layui-form-item layui-form-item-te" style="padding-left: 30%;padding-top: 1%;">
		<label class="layui-form-label">升功率:</label>
		<div class="layui-input-inline">
			<select id="risingPower" name="risingPower" lay-verify="required" readonly>
				<option value="0">无效</option>
				<option value="1">有效</option>
			</select>
		</div>
	</div>
	<div class="layui-form-item layui-form-item-te" style="padding-left: 30%;padding-top: 1%;">
		<label class="layui-form-label">降功率:</label>
		<div class="layui-input-inline">
			<select id="dropPower" name="dropPower" lay-verify="required" readonly>
				<option value="0">无效</option>
				<option value="1">有效</option>
			</select>
		</div>
	</div>
	<div class="layui-form-item layui-form-item-te" style="padding-left: 30%;padding-top: 1%;">
		<label class="layui-form-label">发射机复位:</label>
		<div class="layui-input-inline">
			<select id="transReset" name="transReset" lay-verify="required" readonly>
				<option value="0">无效</option>
				<option value="1">有效</option>
			</select>
		</div>
	</div>
	<div class="layui-form-item layui-form-item-te" style="padding-left: 30%;padding-top: 1%;">
		<label class="layui-form-label">音频增大:</label>
		<div class="layui-input-inline">
			<select id="audioVolumeUp" name="audioVolumeUp" lay-verify="required" readonly>
				<option value="0">无效</option>
				<option value="1">有效</option>
			</select>
		</div>
	</div>
	<div class="layui-form-item layui-form-item-te" style="padding-left: 30%;padding-top: 1%;">
		<label class="layui-form-label">音频减小:</label>
		<div class="layui-input-inline">
			<select id="audioVolumedowen" name="audioVolumedowen" lay-verify="required" readonly>
				<option value="0">无效</option>
				<option value="1">有效</option>
			</select>
		</div>
	</div>
	<div class="layui-form-item layui-form-item-te" style="padding-left: 30%;padding-top: 1%;">
		<label class="layui-form-label">通道设置:</label>
		<div class="layui-input-inline">
			<select id="channelSet" name="channelSet" lay-verify="required" readonly>
				<option value="0">全部设置</option>
				<option value="1">通道1</option>
				<option value="2">通道2</option>
				<option value="3">通道3</option>
				<option value="4">通道4</option>
			</select>
		</div>
	</div>
	<div class="layui-form-item layui-form-item-te" style="padding-left: 40%;padding-top: 2%;">
		<button class="pear-btn pear-btn-primary pear-btn-sm" lay-filter="dict-data-save" lay-submit=""
				type="submit">
			<i class="layui-icon layui-icon-ok"></i>
			提交
		</button>
		<button class="pear-btn pear-btn-sm" type="reset">
			<i class="layui-icon layui-icon-refresh"></i>
			重置
		</button>
	</div>
</form>
<th:block th:include="include :: footer"/>
<script>
	layui.use(['form', 'jquery', 'popup'], function() {
		let form = layui.form;
		let $ = layui.jquery;
		let popup = layui.popup;
		let API_TRANSMITTER_PREFIX = "/api/transmitter/v1/";

		$("#stationCode").val(GetQueryString("stationCode"));
		$("#transCode").val(GetQueryString("transCode"));

		var d = {};
		var t = $('#statusform').serializeArray();
		$.each(t, function() {
			d[this.name] = this.value;
		});

		$.ajax({
			url: API_TRANSMITTER_PREFIX + 'queryStatus',
			type: 'POST',
			contentType: 'application/json;charset=UTF-8',
			data: JSON.stringify(d),
			success: function (data) {
				if (data.code === 0) {
					$("#risingPower").val(data.data.risingPower);
					$("#dropPower").val(data.data.dropPower);
					$("#transReset").val(data.data.transReset);
					$("#audioVolumeUp").val(data.data.audioVolumeUp);
					$("#audioVolumedowen").val(data.data.audioVolumedowen);
					$("#channelSet").val(data.data.channelSet);
					popup.success("获取运行参数成功")
				} else {
					popup.failure(data.msg);
				}
			},
			error: function () {
				popup.failure("获取发射机运行参数接口访问失败!")
			}
		});

		form.on('submit(dict-data-save)', function(data) {
			$.ajax({
				url: API_TRANSMITTER_PREFIX + "setStatus",
				data: JSON.stringify(data.field),
				dataType: 'json',
				contentType: 'application/json',
				type: 'post',
				success: function(result) {
					if (result.success) {
						layer.msg(result.msg, {
							icon: 1,
							time: 1000
						}, function() {
						});
					} else {
						layer.msg(result.msg, {
							icon: 2,
							time: 1000
						});
					}
				}
			})
			return false;
		});
		function GetQueryString(name) {
			const reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
			const r = window.location.search.substr(1).match(reg);
			if (r != null) return unescape(r[2]);
			return null;
		}
	})
</script>
</html>